using Clarity.Phone.Extensions;
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Coding4Fun.Phone.Controls
{
	public class ToastPrompt : PopUp<string, PopUpResult>
	{
		private const string string_0 = "ToastImage";
		protected Image ToastImage;
		private readonly Timer timer_0;
		private TranslateTransform translateTransform_0;
		public static readonly DependencyProperty MillisecondsUntilHiddenProperty = DependencyProperty.Register("MillisecondsUntilHidden", typeof(int), typeof(ToastPrompt), new PropertyMetadata(4000));
		public static readonly DependencyProperty IsTimerEnabledProperty = DependencyProperty.Register("IsTimerEnabled", typeof(bool), typeof(ToastPrompt), new PropertyMetadata(true));
		public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(ToastPrompt), new PropertyMetadata(""));
		public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(ToastPrompt), new PropertyMetadata(""));
		public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ToastPrompt), new PropertyMetadata(new PropertyChangedCallback(ToastPrompt.OnImageSource)));
		public static readonly DependencyProperty TextOrientationProperty = DependencyProperty.Register("TextOrientation", typeof(Orientation), typeof(ToastPrompt), new PropertyMetadata(1));
		public static readonly DependencyProperty TextWrappingProperty = DependencyProperty.Register("TextWrapping", typeof(TextWrapping), typeof(ToastPrompt), new PropertyMetadata(1, new PropertyChangedCallback(ToastPrompt.smethod_0)));
		public int MillisecondsUntilHidden
		{
			get
			{
				return (int)base.GetValue(ToastPrompt.MillisecondsUntilHiddenProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.MillisecondsUntilHiddenProperty, value);
			}
		}
		public bool IsTimerEnabled
		{
			get
			{
				return (bool)base.GetValue(ToastPrompt.IsTimerEnabledProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.IsTimerEnabledProperty, value);
			}
		}
		public string Title
		{
			get
			{
				return (string)base.GetValue(ToastPrompt.TitleProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.TitleProperty, value);
			}
		}
		public string Message
		{
			get
			{
				return (string)base.GetValue(ToastPrompt.MessageProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.MessageProperty, value);
			}
		}
		public ImageSource ImageSource
		{
			get
			{
				return (ImageSource)base.GetValue(ToastPrompt.ImageSourceProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.ImageSourceProperty, value);
			}
		}
		public Orientation TextOrientation
		{
			get
			{
				return (Orientation)base.GetValue(ToastPrompt.TextOrientationProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.TextOrientationProperty, value);
			}
		}
		public TextWrapping TextWrapping
		{
			get
			{
				return (TextWrapping)base.GetValue(ToastPrompt.TextWrappingProperty);
			}
			set
			{
				base.SetValue(ToastPrompt.TextWrappingProperty, value);
			}
		}
		public ToastPrompt()
		{
			base.set_DefaultStyleKey(typeof(ToastPrompt));
			base.IsAppBarVisible = true;
			base.IsBackKeyOverride = true;
			base.Overlay = (Brush)Application.get_Current().get_Resources().get_Item("TransparentBrush");
			base.AnimationType = DialogService.AnimationTypes.SlideHorizontal;
			base.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.method_8));
			base.add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.method_5));
			base.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.method_4));
			this.timer_0 = new Timer(new TimerCallback(this.method_9));
			base.Opened += new EventHandler(this.ToastPrompt_Opened);
		}
		private void method_4(object sender, ManipulationCompletedEventArgs e)
		{
			if (e.get_TotalManipulation().get_Translation().get_X() > 200.0 || e.get_FinalVelocities().get_LinearVelocity().get_X() > 1000.0)
			{
				this.OnCompleted(new PopUpEventArgs<string, PopUpResult>
				{
					PopUpResult = PopUpResult.UserDismissed
				});
				return;
			}
			if (e.get_TotalManipulation().get_Translation().get_X() < 20.0)
			{
				this.OnCompleted(new PopUpEventArgs<string, PopUpResult>
				{
					PopUpResult = PopUpResult.Ok
				});
				return;
			}
			this.translateTransform_0.set_X(0.0);
			this.method_6();
		}
		private void method_5(object sender, ManipulationDeltaEventArgs e)
		{
			TranslateTransform expr_06 = this.translateTransform_0;
			expr_06.set_X(expr_06.get_X() + e.get_DeltaManipulation().get_Translation().get_X());
			if (this.translateTransform_0.get_X() < 0.0)
			{
				this.translateTransform_0.set_X(0.0);
			}
		}
		private void method_6()
		{
			if (this.timer_0 != null)
			{
				this.timer_0.Change(TimeSpan.FromMilliseconds((double)this.MillisecondsUntilHidden), TimeSpan.FromMilliseconds(-1.0));
			}
		}
		private void method_7()
		{
			if (this.timer_0 != null)
			{
				this.timer_0.Change(TimeSpan.FromMilliseconds(-1.0), TimeSpan.FromMilliseconds(-1.0));
			}
		}
		private void method_8(object sender, ManipulationStartedEventArgs e)
		{
			this.method_7();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.translateTransform_0 = new TranslateTransform();
			base.set_RenderTransform(this.translateTransform_0);
			this.ToastImage = (base.GetTemplateChild("ToastImage") as Image);
			if (this.ToastImage != null && this.ImageSource != null)
			{
				this.ToastImage.set_Source(this.ImageSource);
				this.method_10(this.ImageSource);
			}
			this.SetTextOrientation(this.TextWrapping);
		}
		public override void Show()
		{
			if (!this.IsTimerEnabled)
			{
				return;
			}
			base.Show();
		}
		private void ToastPrompt_Opened(object sender, EventArgs e)
		{
			this.method_6();
		}
		private void method_9(object object_0)
		{
			base.get_Dispatcher().BeginInvoke(new Action(this.method_11));
		}
		public override void OnCompleted(PopUpEventArgs<string, PopUpResult> result)
		{
			this.method_7();
			base.OnCompleted(result);
		}
		private static void smethod_0(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			ToastPrompt toastPrompt = dependencyObject_0 as ToastPrompt;
			if (toastPrompt != null && toastPrompt.ToastImage != null)
			{
				toastPrompt.SetTextOrientation((TextWrapping)dependencyPropertyChangedEventArgs_0.get_NewValue());
				return;
			}
		}
		private static void OnImageSource(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			ToastPrompt toastPrompt = dependencyObject_0 as ToastPrompt;
			if (toastPrompt != null && toastPrompt.ToastImage != null)
			{
				toastPrompt.method_10(dependencyPropertyChangedEventArgs_0.get_NewValue() as ImageSource);
				return;
			}
		}
		private void method_10(ImageSource imageSource_0)
		{
			this.ToastImage.set_Visibility((imageSource_0 == null) ? 1 : 0);
		}
		private void SetTextOrientation(TextWrapping textWrapping_0)
		{
			if (textWrapping_0 == 2)
			{
				this.TextOrientation = 0;
			}
		}
		[CompilerGenerated]
		private void method_11()
		{
			this.OnCompleted(new PopUpEventArgs<string, PopUpResult>
			{
				PopUpResult = PopUpResult.NoResponse
			});
		}
	}
}
